package com.example.demo.mapper;

import com.example.demo.mapper.entity.*;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author Lucy
 * @create 2024-02-15 15:27
 */
@Mapper
@Repository
public interface StudentTaskMapper {
    @Select("SELECT * FROM task WHERE task_id = #{taskId}")
    Task selectTaskById(int taskId);
    @Select("SELECT * FROM task WHERE is_main_quest = #{isMainQuest}")
    List<Task> getMORSTasksList(int isMainQuest);
    @Select("SELECT * FROM student_task WHERE student_id = #{studentId}")
    List<StudentTask> selectStudentTasksListByStudentId(int studentId);
    @Select("SELECT * FROM question WHERE bank_id = #{bankId}")
    List<Question> selectQuestionListByBankId(int bankId);
    @Insert("INSERT INTO `student_answer_record` (student_id, question_id, task_id, chosen_answer, is_correct) " +
            "VALUES (#{studentId}, #{questionId}, #{taskId}, #{chosenAnswer}, #{isCorrect}) " )
    @Options(useGeneratedKeys = true, keyProperty = "recordId", keyColumn = "record_id")
    void insertStudentAnswerRecord(StudentAnswerRecord record);
    @Update("UPDATE student_task SET completion_status = #{status} WHERE student_id = #{studentId} AND task_id = #{taskId}")
    void updateCompletionStatus(@Param("studentId")int studentId, @Param("taskId")int taskId, @Param("status")int status);
    @Select("SELECT * FROM item WHERE item_id = #{itemId}")
    Item selectItemById(int itemId);
    @Insert("INSERT INTO `checkin_image` (student_id, task_id, item_id) " +
            "VALUES (#{studentId}, #{taskId}, #{itemId}) " )
    @Options(useGeneratedKeys = true, keyProperty = "imageId", keyColumn = "image_id")
    void insertCheckinImage(CheckinImage image);
    @Update("UPDATE checkin_image SET image_url = #{fileName} WHERE image_id = #{imageId}")
    void insertCheckinImageFileName(@Param("imageId")int imageId, @Param("fileName")String fileName);
    @Update("UPDATE student_task SET completion_status = #{status} , checkin_comments = #{comments} WHERE student_id = #{studentId} AND task_id = #{taskId}")
    void uploadCheckinComments(@Param("studentId")int studentId, @Param("taskId")int taskId, @Param("comments")String comments, @Param("status")int status);
    @Select("SELECT * FROM student_task WHERE student_id = #{studentId} AND task_id = #{taskId}")
    StudentTask selectStudentTask(@Param("studentId")int studentId, @Param("taskId")int taskId);
    @Select("SELECT * FROM checkin_image WHERE student_id = #{studentId} AND task_id = #{taskId} AND item_id = #{itemId}")
    CheckinImage selectCheckinImage(@Param("studentId")int studentId, @Param("taskId")int taskId, @Param("itemId")int itemId);
    @Update("UPDATE checkin_image SET recognition_status = #{recognitionStatus} , checkin_status = #{checkinStatus} , image_url = #{imageUrl} WHERE student_id = #{studentId} AND task_id = #{taskId} AND item_id = #{itemId}")
    void updateCheckinStatus(CheckinImage image);
}
